package cn.buk.tms.dto;

import cn.buk.tms.entity.bill.BillChangeOrder;
import cn.buk.tms.entity.misc.FlightInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;


/**
 * 输出报表时的机票内容：融合了出票，退票，改签的信息，方便在页面暂时的时候，
 * 尽量将同一张票号的退票、改签放在上下挨着的
 */
public class ReportTicketChangeDto extends ReportTicketDto{

	public static ReportTicketChangeDto createReportChangeDto(BillChangeOrder changeOrder) {
		ReportTicketChangeDto dto = new ReportTicketChangeDto();

		BeanUtils.copyProperties(changeOrder, dto);

		dto.setTicketType(2);

		dto.setParvalue(changeOrder.getAirChangeCharge());
		dto.setTax(0);
		dto.setServiceCharge(changeOrder.getServiceCharge());
		dto.setAmount(changeOrder.getAirChangeCharge() + changeOrder.getServiceCharge());
		dto.setPassengerName(changeOrder.getPsgName());

		dto.setDetails(new ArrayList<>());

		for(FlightInfo fltInfo: changeOrder.getFlights()) {
			ReportTicketDetailDto detailDto = ReportTicketDetailDto.createByFlightInfo(fltInfo);
			if (detailDto.getFlightType() == 1) {
				// 新航班信息（改签后的航班信息）
				dto.getDetails().add(detailDto);
			}
		}

		return dto;
	}

	/**
	 * 改签日期：目前使用改签账单的账单日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date changeDate;

	public Date getChangeDate() {
		return changeDate;
	}

	public void setChangeDate(Date changeDate) {
		this.changeDate = changeDate;
	}

}
